<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script type="text/javascript">
    var jsonObj = {
        //number 类型
        'key1': 1234,
        //string 类型
        'key2': 'abcdef',
        //boolean 类型
        'key3': false,
        //Array 类型
        key4: [true, 100, 'xyz'],
        //object 类型
        key5: {
            key5_1: 51,
            key5_2: "key5_2_value"
        },
        //对象数组类型
        "key6": [{
            key6_1_1: 611,
            key6_1_2: 'key6_1_2_value'
        }, {
            key6_2_1: 621,
            key6_2_2: 'key6_2_2_value'
        }]
    };
    //取值操作
    console.log(jsonObj.key1);
    console.log(jsonObj.key2);
    console.log(jsonObj.key3);
    for (var i = 0; i < jsonObj.key4.length; i++) {
        console.log(jsonObj.key4[i]);
    }
    console.log(jsonObj.key5.key5_1);
    console.log(jsonObj.key5.key5_2);
    console.log(jsonObj.key6[0].key6_1_1);
    console.log(jsonObj.key6[0].key6_1_2);
    console.log(jsonObj.key6[1].key6_2_1);
    console.log(jsonObj.key6[1].key6_2_2);


    //转换
    //1.对象转字符串
    var jsonObjStr = JSON.stringify(jsonObj);
    console.log(jsonObj);
    console.log(jsonObjStr);
    //undefined
    console.log(jsonObjStr.key1);
    console.log(jsonObjStr.key2);
    console.log(jsonObjStr.key3);
    //2.字符串转对象
    var obj = JSON.parse(jsonObjStr);
    console.log(obj.key1);
    console.log(obj.key2);
    console.log(obj.key3);
</script>
</body>
</html>